package TUILayer;
import java.util.Scanner;
import ControlLayer.DVDCtr;
import ModelLayer.*;
/**
 * User interface to the DVD controller
 * @author(kbh)
 * @version(2005.03.31)
 * (FEN): 2006.02.24: Comments translated into English
 * (FEN): 2006.03.21: Some changes to the architecture in order to assure layering
 *                    and loose coupling
 * (KBH): 2008.10.24: dvdmenu changed to If                   
 */

public class DvdUI
{
    private DVDCtr dvdCtr;//DVD UI must know the DVD controller
    private DvdContainer dc;
    private Dvd thisdvd;
    
    public DvdUI()
    {
        dvdCtr= new DVDCtr();
        
        
    }
    
    public void start()
    {
        dvdMenu();
    }
    
    public void dvdMenu()
    {   
        boolean exit = false;
        while(!exit)
        {
            //show menu and return the user's choise
            int choise =   writeDVDMenu();
            if (choise == 1)
            {
                findDVD();
            }
            else{if(choise == 2){
                   createDVD();
                }
                else{
                    if(choise == 3){
                        createCopy();
                    }
                    else{
                        if(choise == 4){
                             deleteDVD();
                        }
                        else{
                            if(choise == 5){
                                listDvd();
                            }
                            else{
                                exit = true;
                            }//end else
                        }//end else
                    }//end else
                }//end else
            }//end else
        }//end while
    }
    private int writeDVDMenu()
    {
           // creates an object keyboard to read data from the keyboard
            Scanner keyboard = new Scanner(System.in);
            System.out.println(" *** DVD Menu ***");
            System.out.println(" (1) Show DVD information");
            System.out.println(" (2) Create DVD description");
            System.out.println(" (3) Create DVD copy");
            System.out.println(" (4) Delete DVD");
            System.out.println(" (5) Show current DVD list");
            System.out.println(" (6) Return");
            System.out.print("\n Make your choise: ");
            
            int choise = keyboard.nextInt();
            return choise;
    }
    
    /**
     * Print a text and takes input from keyboard
     * @param text Print text
     * @return str Return the input from the keyboard 
     */
    private String inputtext(String text)
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.print(text + ": ");
        String str = keyboard.nextLine();
        return str;
    }
    
    /**
     * Print a text and takes input from keyboard
     * @param text Print text
     * @return no Return the input from the keyboard as a long
     */
    private long inputnumber(String text)
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.print(text + ": ");
        String str = keyboard.nextLine();
        long no = Long.parseLong(str.trim());  // convert String 2 long
        return no;
    }
    /**
     * En test af keyinput
     */
    public void testkey()
    {
        String str = inputtext("Skriv en teksten her");
        long no = inputnumber("skriv er tal her");
    }
    
    /**
     * Finds a dvd
     * Takes indput from the keyboard
     * call dvdCtr.findDVD() with id of the dvd
     */
    public void findDVD()
    {
        long n = inputnumber("Type DVD number");
        dvdCtr.findDVD(n);
    }
    
    /**
     * Create a new dvd
     * Takes indput from the keyboard: id, title, kunstner, udgivelsesdato
     * Call dvdCtr.createDvd() with the input
     */
    public void createDVD()
    {
        long dvdid = inputnumber("Type DVD id");
        String title = inputtext("Type DVD title");
        String kunstner = inputtext("Type DVD kunstner");
        String udgivelsesdato = inputtext("Type DVD udgivelsesdato");
        dvdCtr.createDvd(dvdid, title, kunstner, udgivelsesdato);
    }
    
    /**
     * Create a copy of a dvd
     * Takes indput from the keyboard: id, serialnr, anskdato, anskafpris, description
     * Call dvdCtr.createCopy() with the input
     */
    public void createCopy()
    {
        long dvdid = inputnumber("Type in the id of the DVD, you wish to make a copy of");
        String serienr = inputtext("Type in the serial number of the DVD");
        String anskafdato = inputtext("Type in todays Date");
        String anskafpris = inputtext("Type in how much the copy costed");
        String dvdtext = inputtext("Type in todays Date");
        dvdCtr.createCopy(dvdid, serienr, anskafdato, anskafpris, dvdtext);
    }
    
    /**
     * Delete a dvd
     * Takes indput from the keyboard: id
     * Call dvdCtr.deleteDvd with the input
     */
    public void deleteDVD()
    {
        long dvdid = inputnumber("Type in the id number of the DVD you wish to delete");
        dvdCtr.deleteDvd(dvdid);
    }
    
    /**
     * Prints all dvd in the DvdContainer
     */
    public void listDvd()
    {
        dvdCtr.listDvd();
        
    }
    
    
}